package com.bckj.fastboot.core.extra.stage;

import lombok.RequiredArgsConstructor;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

@RequiredArgsConstructor
public class StageBeanRegister implements BeanPostProcessor {

    private final StageRepository stageRepository;

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if (bean instanceof Stage<?> stage && StringUtils.isNotBlank(stage.getStageId())) {
            stageRepository.add(stage);
        }
        return bean;
    }
}
